#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;

int n;
bool isc[N];
int pri[N], pnum;

void sieve(int n) {
	rep(i, 2, n) {
		if(!isc[i]) pri[++pnum] = i;
		rep(j, 1, pnum) {
			int x = i * pri[j]; if(x > n) break;
			if(isc[x]) break; isc[x] = true;
		}
	}
}

bool vis[N];

void solve() {
	n = in;
	rep(i, 1, n) vis[i] = 0;
	vec tpot;
	rep(j, 1, pnum) {
		int x = pri[j];
		if(x * 2 > n) break;
		tpot.eb(x);
	}
	reverse(tpot.begin(), tpot.end());
	veg ret; vec res;
	for(auto x : tpot) {
		vec pot;
		rep(i, 1, n) {
			int y = x * i; if(y > n) break;
			if(!vis[y]) pot.eb(y), vis[y] = true;
		}
		if(pot.size() <= 1) continue;
		sort(pot.begin(), pot.end(), [&](int x, int y) { return (x & 1) > (y & 1); });
		rep(j, 1, pot.size() - 1) {
			ret.eb(pot[j], pot[j - 1]);
			j++;
		}
		if(pot.size() & 1) res.eb(pot.back());
	}
	rep(j, 1, (int)res.size() - 1) ret.eb(res[j], res[j - 1]), j++;
	printf("%d ", ret.size());
	for(auto v : ret) printf("%d %d ", v.fi, v.se);
	puts("");
}

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	sieve(100000);
	for(int T = in; T; T--) solve(); return 0;
}
